# -*- coding: utf-8 -*-
import re
from common import get_from_yd
from common import sql_script


def get_ket():
    p = re.compile(r'(^.+?)\s+(\W+)$')
    f = open("pet1.txt")
    ket = {}
    for line in f:
        m = p.search(line)
        if m:
            ket[m.groups()[0]] = m.groups()[1]
        else:
            print "######"
            print line
    return ket


def get_pet2():
    p = re.compile(r"(^.+?)\(.+\)+(.+)$")
    f = open("pet2.txt")
    ket = {}
    for line in f:
        m = p.search(line)
        if m:
            ket[m.groups()[0].strip()] = m.groups()[1].strip()
        else:
            print "######"
            print line
    return ket


def main():
    ket = get_ket()
    pet = get_pet2()
    pet.update(ket)
    #for i in pet:
    #    get_from_yd.get_audio(i, "/Users/stack/python/python3721/pet/voice")
    #sql_script.insert_list(pet.items(), "112.126.90.160", 57, "剑桥PET词汇", 4852)
    sql_script.insert_list(pet.items(), "60.205.94.133", 54, "剑桥PET词汇", 4598)
    print len(pet.items())


if __name__ == '__main__':
    main()
